/**
 * Copyright ©2016-2020 northkingbpo Corporation, All Rights Reserved
 * http://www.northkingbpo.net/
 */
package profile.hujia.http.client.jersey.server;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
 * class info
 *
 * @author hujia
 * @date 2018/10/26 21:58
 */
@Service
@Slf4j
public class RemoteCallService {

    private final String url = "http://115.28.188.41:50001/queue/";

    @Autowired
    private Client jerseyClient;

    public void getList() {
        WebTarget target = jerseyClient.target(url).path("getList")
                .queryParam("busiType", "busiType-3333")
                .queryParam("currentPage", "1")
                .queryParam("item", "item-4444")
                .queryParam("number", "10")
                .queryParam("orgBusiness", "orgBusiness-1111")
                .queryParam("workqueue", "workqueue-2222");
        Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON);

        Response response = builder.get();
        String result = response.readEntity(String.class);
        log.info("the status code is " + response.getStatus());
        log.info("the MediaType is " + response.getMediaType());
        log.info(result);
    }

    public void add() {
        String json = "{\"id\":\"id_000\",\"name\":\"work-item-00\",\"engineAddress\":null," +
                "\"rootActId\":null,\"priority\":0,\"rootStartTime\":null,\"organizationalunit\":" +
                "\"orgnizationalunit00\",\"state\":3,\"obtainedTime\":null,\"submitedTime\":null," +
                "\"workqueue\":null,\"transitRefData5\":\"data00-0\",\"busiType\":\"busiType00\"," +
                "\"orgBusiness\":\"orgBusiness00\"}";
        WebTarget target = jerseyClient.target(url).path("add");
        Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON);
        Response response = builder.post(Entity.entity(json, MediaType.APPLICATION_JSON));
        log.info(response.toString());
    }
}
